package com.colin.aiyi.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.colin.aiyi.R;
import com.colin.aiyi.entity.User;
import com.colin.aiyi.entity.response.BaseResponse;
import com.colin.aiyi.ui.login.LoginAc;
import com.colin.aiyi.ui.register.ImpPRegister;
import com.colin.aiyi.view.ShowMsgUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by hl on 2017/5/19.
 */

public class PasswdSettingAc extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.img_logo)
    ImageView imgLogo;
    @BindView(R.id.edit_phone1)
    EditText editPhone1;
    @BindView(R.id.edit_phone2)
    EditText editPhone2;
    @BindView(R.id.text_register)
    TextView textRegister;
    @BindView(R.id.text_msg)
    TextView textMsg;
    private String phoneNumber;
    private String strEidtVcode;
    String passwd;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_pw_setting);
        ButterKnife.bind(this);
        user = new User();
        user.setTelNo(getIntent().getStringExtra("phone"));
        user.setMessageCode(getIntent().getStringExtra("vcode"));
        iPresenter = new ImpPRegister();
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.text_register:
                if (!checkEmpty(new String[]{"请输入密码", "请重复输入密码"},
                        new TextView[]{editPhone1, editPhone2}, textMsg)) {
                  return;
                }
                String passwd1=editPhone1.getText().toString().replace(" ","");
                String passwd2=editPhone2.getText().toString().replace(" ","");
                if (!passwd1.equals(passwd2)){
                    textMsg.setText("两次输入密码不相同");
                    return;
                }
                user.setPassword(editPhone1.getText().toString().trim());
                iPresenter.setIView(this);
                iPresenter.login_register(user);
                ShowMsgUtil.showLoadingDialog(this);
                break;
        }
    }


    @Override
    public <T> void netResponse(T t) {
        ShowMsgUtil.hideLoadingDialog();
        if (t != null) {
            if (((BaseResponse) t).getCode() == 200) {
                showMsg("注册成功");
                Intent intent = new Intent(this, LoginAc.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                finish();
            } else {
                showMsg(((BaseResponse) t).getMessage());
            }
        }
    }


}
